package com.wechat.api.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @description:
 * @date: 2022/5/19
 * @author: shendong
 */
@Getter
@AllArgsConstructor
public enum WeChatEnums {
    LOGIN("https://api.weixin.qq.com/sns/jscode2session","GET");

    private String url; // 接口地址
    private String reqMethod;

    WeChatEnums(String url){
        this(url,"POST");
    }

    public String initUrl(){
        if (reqMethod.equals("GET")) {

           return jsonToGet(url);
        }
        return url;
    }

    /**
     * json格式转Get
     * @param body
     * @return
     */
    private String jsonToGet(String body){
        return body.replace("{", "").replace("}", "").
                replace("\"", "").replace("'", "").
                replace(":", "=").replace(",", "&");
    }
}
